<template>
	<view class="content">
		<view class="record-list" v-if="orderList.length>0">
			<view class="record_item" v-for="(item,index) in orderList" :key="index">
        <view class="order-id">订单编号：{{item.chargeOrderId}}</view>
				<view class="name">{{item.stationName}}</view>
        <view class="item">
          <view class="label">充电时长</view>
          <view class="value">{{getTime(item.startTime,item.endTime)}}</view>
        </view>
        <view class="item">
          <view class="label">充电度数</view>
          <view class="value">{{item.totalPower}}度</view>
        </view>
        <view class="item">
          <view class="label">充电金额</view>
          <view class="value">{{item.totalElecMoney}}元</view>
        </view>
        <view class="item">
          <view class="label">服务费</view>
          <view class="value">{{item.totalSeviceMoney}}元</view>
        </view>
        <view class="item">
          <view class="label">日期</view>
          <view class="value">{{item.createTime}}</view>
        </view>
        <view class="item">
          <view class="label">订单金额</view>
          <view class="value item-price"><text>¥</text> {{item.totalMoney}}</view>
        </view>
        <view class="item">
          <view class="label">优惠金额</view>
          <view class="value item-price"><text>-￥</text> {{item.discAmt}}</view>
        </view>
        <view class="item real-pay">
          <view class="label">实付金额</view>
          <view class="value item-price"><text>{{item.realAmt}}</text>元</view>
        </view>
			</view>
		</view>
<!--		<view class="hint" v-else>暂无数据!</view>-->
    <empty v-else></empty>
	</view>
</template>

<script>
	import {
		checkChargeOrders,
		fuelOrders
	} from '@/api/index'
  import empty from "@/components/empty.vue";
	export default {
    components: {empty},
		data() {
			return {
				openId: uni.getStorageSync('userOpenId'),
				orderList: [], //订单列表
				total: 0,
			}
		},
		onLoad() {
			this.getOrders()
		},
		methods: {
			getTime(createTime, endTime) {
				var startTime = new Date(createTime); // 开始时间
				var nowTime = new Date(endTime); // 结束时间
				var diff = nowTime.getTime() - startTime.getTime(); // 时间差值（单位为毫秒）
				var days = Math.floor(diff / (24 * 3600 * 1000)); // 计算相差的天数
				var hours = Math.floor(diff % (24 * 3600 * 1000) / (3600 * 1000)); // 计算小时数
				var minutes = Math.floor(diff % (3600 * 1000) / (60 * 1000)); // 计算分钟数
				var seconds = Math.floor(diff % (60 * 1000) / 1000); // 计算秒数
				hours = days == 0 ? hours : hours + 24 * days
				// console.log(hours + "小时" + minutes + "分钟");
				return hours == 0 ? minutes + "分钟" : hours + "小时" + minutes + "分钟"
			},
			// 查询订单
			getOrders(type) {
				checkChargeOrders({
					openid: this.openId,
					paidStatus: 1,
					pageNum: 1,
					pageSize: 10
				}).then(res => {
					if (res.rows.length > 0) {
						this.orderList = res.rows
						this.total = res.total
						return
					}
					this.orderList = []
					this.total = 0
					console.log(res, 'checkChargeOrders')
				}).catch(error => {
					console.log(error)
				})
			},

			// // 查询进行中的订单
			// getChargrHaveOrders () {
			//   checkChargrHaveOrders({
			//     openid: this.openId,
			//   }).then(res => {
			//     console.log(res, 'checkChargrHaveOrders')
			//   }).catch(error => {
			//     console.log(error)
			//   })
			// }
		}
	}
</script>

<style lang="scss">
	.content {
		.record-list {
			padding: 24rpx 30rpx;

			.record_item {
				background: #ffffff;
				border-radius: 16rpx 16rpx 16rpx 16rpx;
				//padding: 32rpx 32rpx;
				margin-bottom: 20rpx;
        padding-bottom: 20upx;
        .order-id{
          color: #1B1B1B;
          font-size: 28upx;
          padding: 24upx 20upx;
          line-height: 44upx;
          border-bottom: 1px solid #F0F1F2;
        }

        .item{
          box-sizing: border-box;
          padding: 0 20upx;
          line-height: 84upx;
          font-size: 28upx;
          color: #6A6A6A;
          display: flex;
          justify-content: space-between;
          align-items: center;
          .value{
            color: #1B1B1B;
            font-weight: 500;
          }
          .item-price{
            color: #F57546;
          }
        }
        .real-pay{
          font-weight: 500;
          .item-price{
            text{
              margin-right: 8upx;
              font-size: 44upx;
            }
          }
        }

				.name {
					font-size: 34rpx;
					color: #2d2b2a;
					line-height: 48rpx;
					margin-bottom: 8rpx;
          margin-top: 20upx;
          padding: 0 20upx;
          font-weight: 500;

					text {
						font-size: 28rpx;
						color: #2d2b2a;
					}
				}

				.record_info {
					margin: 16rpx 0rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;

					.pr {
						display: inline-block;
						font-size: 26rpx;
						color: #939391;
						line-height: 40rpx;
						text-align: center;
					}

					.card {
						margin-left: 24rpx;
						display: inline-block;
						text-align: center;
						font-size: 26rpx;
						color: #939391;
						line-height: 40rpx;
					}
				}

				.charge-time {
					font-size: 26rpx;
					color: #939391;
					line-height: 36rpx;
				}

				.charge-number {
					font-size: 26rpx;
					color: #939391;
					line-height: 36rpx;
					margin: 16rpx 0rpx;
				}

				//.order-id {
				//	font-size: 26rpx;
				//	color: #939391;
				//	line-height: 36rpx;
				//}

				.record {
					display: flex;
					align-items: center;
					justify-content: space-between;

					.time {
						font-size: 26rpx;
						color: #939391;
						line-height: 36rpx;
					}

					.price {
						font-size: 40rpx;
						font-weight: 500;
						color: #e56646;
						line-height: 44rpx;

						text {
							font-size: 28rpx;
						}
					}
				}
				.order-price{
					margin-top: 20rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;
					.title {
						font-size: 26rpx;
						color: #939391;
						line-height: 36rpx;
					}
					
					.price {
						font-size: 40rpx;
						font-weight: 500;
						color: #e56646;
						line-height: 44rpx;
					
						text {
							font-size: 28rpx;
						}
					}
				}
			}

			.record_item:nth-last-child(1) {
				margin-bottom: 0px;
			}
		}

		.hint {
			width: 100%;
			height: 100vh;
			display: flex;
			align-items: center;
			justify-content: center;
			font-size: 42rpx;
			color: #c0c0c0;
			letter-spacing: 10rpx;
		}
	}
</style>